package xyz.zcq.zcqrpc.registry;

import xyz.zcq.zcqrpc.model.ServiceMetaInfo;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 注册中心服务本地缓存
 */
public class RegistryServiceCache {

    /**
     * 缓存
     * key："{serviceName}:{serviceVersion}"
     */
    private final Map<String, List<ServiceMetaInfo>> cache = new HashMap<>();

    /**
     * 写缓存
     *
     * @param key      键
     * @param infoList 服务元信息集合
     */
    public void writeCache(String key, List<ServiceMetaInfo> infoList) {
        cache.put(key, infoList);
    }

    /**
     * 获取缓存
     *
     * @param key 键
     * @return 服务元信息集合
     */
    public List<ServiceMetaInfo> getCache(String key) {
        return cache.get(key);
    }

    /**
     * 清空缓存
     */
    public void clearCache(String key) {
        cache.remove(key);
    }

}
